/*
 * @Author: 缄默
 * @Date: 2021-12-12 15:18:30
 * @LastEditors: 缄默
 * @LastEditTime: 2021-12-26 17:26:26
 */
//策略模式

#include <iostream>
#include <vector>
#include <string>

using namespace std;

class Strategy {
public:
    virtual void strategyMethod() = 0;

    virtual ~Strategy() { }
};


class ConcreteStrategy1 : public Strategy {
public:
    void strategyMethod() {
        cout << "ConcreteStrage1 callled..." << endl;
    }
};

class ConcreteStrategy2 : public Strategy {
public:
    void strategyMethod() {
        cout << "ConcreteStrage2 callled..." << endl;
    }
};

class Context {
private:
    Strategy* _strategy;

public:
    Context(Strategy* strategy) {
        _strategy = strategy;
    }

    void setStrategy(Strategy* strategy) {
        _strategy = strategy;
    }

    Strategy* getStrategy() {
        return _strategy;
    }

    void strategyMethod() {
        _strategy->strategyMethod();
    }
};

int main() {
    ConcreteStrategy1* concreteStrtegy1 = new ConcreteStrategy1();
    ConcreteStrategy2* concreteStrtegy2 = new ConcreteStrategy2();
    Context* context = new Context(concreteStrtegy1);
    context->strategyMethod();
    context->setStrategy(concreteStrtegy2);
    context->strategyMethod();

    delete concreteStrtegy1;
    delete concreteStrtegy2;
    delete context;

    return 0;
}